home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / res / blog / selfBlog / mobileIndex.php < prev    next >
PHP Script  |  2010-05-19  |  8KB  |  188 lines

  1. <?php
  2. /**
  3.  * RSS feed viewer
  4.  *
  5.  * PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   NA
  14.  * @package    NA
  15.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  16.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id:$
  19.  * @link       http://www.weezo.net
  20.  * @since      File available since Release 1.4.0
  21.  */
  22.  
  23. require(INCLUDE_DIR.'mobileFunctions.php');
  24.  
  25. $isAdmin=WEnv::user()->isAdministrator();
  26.  
  27. // Get an array with all blog's messages. This array is used for previous/next buttons and for history
  28. $allMessages=getMessagesList(false,false);
  29. $messages=getMessagesList($dateTo, $dateFrom);
  30. if(!count($messages)) die('<br><br><center>'.cfCaption('blogNoPost').'</center><br><br><br>');
  31.  
  32.  
  33. /*
  34.  ***************************************************************************************************************************
  35.  * Process POST commands
  36.  ***************************************************************************************************************************
  37.  */
  38. if(isset($_POST['action']) && $_POST['action']=='showComments'){
  39.     cfAsyncHeader();
  40.     $key=substr($_POST['value'],3);
  41.     if(isset($messages[$key])){
  42.         $html='<div class="frame2Header">'.cfCaption('blogComments',count($comments=getCommentsList($messages[$key]))).'</div>';
  43.         foreach ($comments as $comment){
  44.             $html.='<div class="frame3"><div class="frame3Header">'.cfCaption('blogCommentTitle',$comment['author']).'</div>';
  45.             $html.=$comment['body'];
  46.             $html.='<br><br>';
  47.             if(isset($comment['eMail'])) $html.=outMailSafe($comment['eMail'],0).'<br>';
  48.             if(isset($comment['link'])) {
  49.                 if(strtolower(substr($comment['link'],0,4))!='http') $link='http://'.$comment['link']; else $link=$comment['link'];
  50.                 $html.='<a href="'.$link.'" target="_blank">'.cfUTF8Encode($comment['link']).'</a>';
  51.             }
  52.             $html.='</div>';
  53.         }
  54.         if($html) echo cfAsyncXMLInnerHTMLbyId($html,$_POST['value']);
  55.     }
  56.     echo cfAsyncXMLJSaction('mwl.liUnsel("'.$_POST['value'].'")');
  57.     die(cfAsyncFooter());
  58. }
  59.  
  60.  
  61. /*
  62.  ***************************************************************************************************************************
  63.  * Insert HEAD, FORMS and JAVASCRIPT functions
  64.  ***************************************************************************************************************************
  65.  */
  66. $editBt=($isAdmin)?mfButton(false,'javascript:newMsgShow(1)',outIcon('edit')):'';
  67. mfInsertHead(array('topControlsExtra'=>$editBt));
  68. ?>
  69. <form name="miscAction" action="index.php" enctype="multipart/form-data" method="POST" style="display:none;">
  70. <input name="action" id="action" type="hidden">
  71. <input name="value" id="value" type="hidden">
  72. <input type="hidden" name="resId" value="<?php echo $_SESSION['activeResourceId']; ?>">
  73. </form>
  74.  
  75. <script type="text/javascript">
  76. function mas(a,v,s){
  77.     if(s) return sendData('action='+a+'&value='+v);
  78.     dgi("action").value=a;
  79.     dgi("value").value=v;
  80.     D.forms.miscAction.submit();
  81. }
  82. function sc(n){mwl.liSel(n);mas('showComments',n.id,1)}
  83. function goMsg(ts){mas('prevNext',ts);}
  84. function deleteMsg(id){if(confirm("<?php echo cfCaption('blogConfirmDelete');?>")) mas('delete',id)}
  85. function newMsgShow(v){dgi('newMsgForm').style.display=(v)?'':'none'; dgi('blogBody').style.display=(v)?'none':'';if(v) dgn('newMessageTitle').focus()}
  86. function newMsgSend(){dgi('newMsgForm').submit()}
  87. </script>
  88. <?php
  89.  
  90. // New post form
  91. if($isAdmin){
  92. ?>
  93. <form id="newMsgForm" method="post" enctype="multipart/form-data" style="display:none">
  94. <div class="frame1Header"><?php echo cfCaption('genTitle');?></div>
  95. <input type="text" name="newMessageTitle" style="width:100%"><br>
  96.  
  97. <div class="frame1Header"><?php echo cfCaption('explorerFileSendMessage');?></div>
  98.  
  99. <textarea style="width:100%;height:10em" name="newMessageBody"></textarea>
  100. <?php
  101.     echo mfListTable();
  102.     echo mfListItem('onclick="newMsgSend()"',outImage(outIcon('save'),false,'class="imgW"'),false,cfCaption('blogPostNewMessage'));
  103.     echo mfListItem('onclick="newMsgShow(0)"',outImage(outIcon('cancel'),false,'class="imgW"'),false,cfCaption('genCancel'));
  104.     echo '</table></form>';
  105. }
  106.  
  107. // Messages
  108. echo '<div class="frame1" id="blogBody">';
  109.  
  110. // Get timestamps of 1st and last post
  111. $minMax=getMinMaxDate();
  112.  
  113.  
  114. // "Next messages" button
  115. if($minMax){
  116.     reset($messages); // position on first (most recent) of displayed messages
  117.     if(getTimeStamp(current($messages)->getAttribute('date'))<$minMax['max']){ // If this message is not the most recent
  118.         // Find this message in entire messages list.
  119.         reset($allMessages); for($i=0;$i<count($allMessages);$i++) {if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break; next($allMessages);}
  120.         // Move maxPostPerPage steps backward
  121.          for($i=0;$i<cfRGetVar('maxPostPerPage');$i++) @prev($allMessages); if(!current($allMessages)) reset($allMessages);
  122.          $nextTS=getTimeStamp(current($allMessages)->getAttribute('date'));
  123.         // Display button
  124.         echo mfListTable();
  125.         echo mfListItem('onclick="goMsg('.$nextTS.')"',' ',false,cfCaption('blogNextPosts'),false,outImage(outIcon('medUp')),false).'</table>';
  126.     }
  127. }
  128.  
  129.  
  130. /**
  131.  * Display messages
  132.  */
  133. $nbDisplayedMessages=0;
  134. foreach ($messages as $key=>$message){
  135.     if(cfRGetVar('maxPostPerPage') && cfRGetVar('maxPostPerPage') <= $nbDisplayedMessages) break; // Limit number of displayed messages
  136.  
  137.     // Title & delete button
  138.     $del=($isAdmin)?mfButton('','javascript:deleteMsg('.$message->getAttribute('ID').')',outIcon('cancel'),cfCaption('genDelete'),'supprBt'.$message->getAttribute('ID'),'style="margin-right:3px;"'):'';
  139.     echo '<div class="frame1Header">'.$del.($message->getElementsByTagname('title')->item(0)->nodeValue).'</div>';
  140.  
  141.     // Top image
  142.     $body=$message->getElementsByTagname('body')->item(0);
  143.     $image=$message->getElementsByTagname('image');
  144.     if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='top') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
  145.  
  146.     // Message body
  147.     echo $body->nodeValue;
  148.  
  149.     // Bottom image
  150.     if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='bottom') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
  151.  
  152.     // Comments
  153.     if(cfRGetVar('commentsAllowed') && count($comments=getCommentsList($message))){
  154.         echo '<div class="frame2" id="cmt'.$key.'" onclick="sc(this)"><div class="frame2Header">'.outImage(outIcon('medPlus'),false,'class="ico"').cfCaption('blogComments',count($comments)).'</div></div>';
  155.     }
  156.  
  157.     // Message date
  158.     $postDate=cfCaption('blogPosted',cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), getTimeStamp($message->getAttribute('date')))));
  159.  
  160.     // Display footer
  161.     echo '<br><br>'.$postDate.'<br>';
  162.  
  163.     $nbDisplayedMessages++;
  164. }
  165.  
  166. // "Previous messages" button
  167. if($minMax){
  168.     reset($messages); for($i=1;$i<cfRGetVar('maxPostPerPage');$i++) @next($messages); // Position on last (oldest) message
  169.     if(!current($messages)) end($messages); // If $messages contains less than maxPostPerPage, go to last message
  170.  
  171.     if(getTimeStamp(current($messages)->getAttribute('date'))>$minMax['min']){ // If this message is not the most recent
  172.         // Find this message in entire messages list.
  173.         reset($allMessages);
  174.         for($i=0;$i<count($allMessages);$i++) {
  175.             if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break;
  176.             next($allMessages);
  177.         }
  178.         @next($allMessages); // Move one step forward
  179.         $previousTS=getTimeStamp(current($allMessages)->getAttribute('date'));
  180.         // Display button
  181.         echo mfListTable();
  182.         echo mfListItem('onclick="goMsg('.$previousTS.')"',' ',false,cfCaption('blogPreviousPosts'),false,outImage(outIcon('medDown')),false).'</table>';
  183.     }
  184. }
  185. ?>
  186. </div>
  187. </body>
  188. </html>